package com.gxa.ehome.aop;


import org.apache.ibatis.session.SqlSession;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.mybatis.spring.SqlSessionTemplate;



//要实现一个切面编程，使用配置的方式
public class TxAspect {

   // @Resource(name="sqlSession")
    SqlSessionTemplate sqlSession;

    @Pointcut("execution(* com.gxa.ehome.service.*.*(..))")
    public void poinCut(){

    }
       //前置通知
    @Before("poinCut()")
    public void before(JoinPoint joinPoint){

    }
    @AfterReturning("poinCut()")
    public void afterReturning(){

        sqlSession.close();
    }
    //后置抛出通知
    @AfterThrowing("poinCut()")
    public void afterThrowing(ProceedingJoinPoint proceedingJoinPoint){

      sqlSession.rollback();
    }
    @After("poinCut()")
    public void after(){
        sqlSession.commit();

    }

}
